/*

	Unit tests for Date class

*/

#include "../date.h"

//@author A0101728M
bool operator == (const Date& lhs, const Date& rhs){
	return lhs.get() == rhs.get();
}

TEST(dateTest, testCreation){
	Date default = Date();
	EXPECT_EQ(default, Date(1970, 1, 1, 0, 0));

	boost::posix_time::ptime timeNow = boost::posix_time::second_clock::local_time();
	Date dateNow = Date(timeNow);
	Date dateSetNow = Date();
	dateSetNow.set(timeNow);
	EXPECT_EQ(dateNow, dateSetNow);
}

/*TEST(dateTest, getSet){

}*/

TEST(dateTest, testAddition){
	Date original = Date();
	Date newDate = Date(1980, 1, 13, 5, 5);
	original.addDays(5);
	original.addHours(5);
	original.addMinutes(5);
	original.addWeeks(1);
	original.addYears(10);
	EXPECT_EQ(original, newDate);
}

//@author A0105541U
TEST(dateTest, testFromString) {
	Date date;
	date.fromString("2013-2-29");
	EXPECT_EQ(date.toString(), "not-a-date-time");
	date.fromString("2013-2-28");
	EXPECT_EQ(date.toString(), "2013/Feb/28 23:59");
	date.fromString("2012-2-28");
	EXPECT_EQ(date.toString(), "2012/Feb/28 23:59");
	date.fromString("2012-feb-28 23:59");
	EXPECT_EQ(date.toString(), "2012/Feb/28 23:59");
	date.fromString("2012-Nov-28");
	EXPECT_EQ(date.toString(), "2012/Nov/28 23:59");
	date.fromString("");
	EXPECT_EQ(date.toString(), "not-a-date-time");
	date.fromString("2012-Dec-18 23:591");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("2012-Dec-18 23:60");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("2012-Dec-18 23:1");
	EXPECT_EQ(date.toString(), "2012/Dec/18 23:01");

	date.fromString("2012-Dec-18 23:-1");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("2012-1-18 -1:03");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("-3-3-3");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("-1-18 1:03");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("0-21 1:03");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("11-31 1:03");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("may 31 1:03");
	EXPECT_EQ(date.toString(), "2013/May/31 01:03");

	date.fromString("may 31 1:0003");
	EXPECT_EQ(date.toString(), "2013/May/31 01:03");

	date.fromString("234232343243223:23432433242332423");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	
	date.fromString("24:04");
	EXPECT_EQ(date.toString(), "not-a-date-time");

	date.fromString("the day ");
	ASSERT_EQ(date.toString(), "not-a-date-time");

	date.fromString("");
	ASSERT_EQ(date.toString(), "not-a-date-time");

	date.fromString("   rubbish text that >.< you have to  parse \" \' -2 -6  \\ // ");
	ASSERT_EQ(date.toString(), "not-a-date-time");


	/* relative date time
	date.fromString("friday");
	EXPECT_EQ(date.toString(), "2013/Nov/15 23:59");
	date.fromString("tomorrow 9:30pm");
	EXPECT_EQ(date.toString(), "2013/Nov/11 21:30");
	date.fromString("21:30pm");
	EXPECT_EQ(date.toString(), "not-a-date-time");
	*/


}